package com.example.administrator.kotiln

import android.content.Intent
import android.os.Bundle
import android.view.KeyEvent
import android.view.View
import android.widget.Toast
import com.example.administrator.kotiln.base.BaseActivity
import com.example.administrator.kotiln.ui.*
import kotlinx.android.synthetic.main.activity_head.*
import kotlinx.android.synthetic.main.activity_main.*
import java.util.*

class MainActivity : BaseActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        //val tv = findViewById(R.id.tv) as TextView

        initView()
        initValue()
    }

    private fun initValue() {
        back.setVisibility(View.INVISIBLE)
        title_tv.text = "主页"
    }

    private fun initView() {
        //ToastUtils.showToast(this, "00000")

        // ToastUtils.showToast(this@MainActivity, "aaa")
        tv.setTextColor(resources.getColor(R.color.tvs))
        tv.text = "secondactivity"
        tv.setOnClickListener {
            //            val intent = Intent(this@MainActivity, SecondActivity::class.java)
//            startActivity(intent)
            openActivity(SecondActivity::class.java)
        }
        lv.setOnClickListener {
            //            val intent = Intent(this@MainActivity, ListViewActivity::class.java)
//            startActivity(intent)
            openActivity(ListViewActivity::class.java)
        }
        threadActivity.setOnClickListener {
            //            val intent = Intent(this@MainActivity, ThreadActivity::class.java)
//            startActivity(intent)
            openActivity(ThreadActivity::class.java)
        }

        testsocket.setOnClickListener {
            //            val intent = Intent(this@MainActivity, SocketActivity::class.java)
//            startActivity(intent)
            openActivity(SocketActivity::class.java)
        }
        testsockettwo.setOnClickListener {
            //            val intent = Intent(this@MainActivity, SocketTwoActivity::class.java)
//            startActivity(intent)
            openActivity(SocketTwoActivity::class.java)
        }
        video.setOnClickListener {
            //            val intent = Intent(this@MainActivity, VideoActivity::class.java)
//            startActivity(intent)
            openActivity(VideoActivity::class.java)
        }
        viewpager.setOnClickListener {
            //            val intent = Intent(this@MainActivity, ViewPagersActivity::class.java)
//            startActivity(intent)
            openActivity(ViewPagersActivity::class.java)
        }
        animator.setOnClickListener {
            //            val intent = Intent(this@MainActivity, AnimatorActivity::class.java)
//            startActivity(intent)
            openActivity(AnimatorActivity::class.java)
        }
        viewpagergrildview.setOnClickListener {
            val intent = Intent(this@MainActivity, ViewPagerGrildViewActvity::class.java)
            startActivity(intent)
            //openActivity(ViewPagerGrildViewActvity::class.java)
        }
        gundong.setOnClickListener {
            val intent = Intent(this@MainActivity, GunDongActivity::class.java)
            startActivity(intent)
            //openActivity(GunDongActivity::class.java)
        }
        websocket.setOnClickListener {
            val intent = Intent(this@MainActivity, OkHttpWebSocketActivity::class.java)
            startActivity(intent)
        }

        TabLayoutOnlyActivity.setOnClickListener {
            val intent = Intent(this@MainActivity, TabLayoutOnlyActivity::class.java)
            startActivity(intent)
        }
        okwebsocket.setOnClickListener {
            val intent = Intent(this@MainActivity, WebSocketActivity::class.java)
            startActivity(intent)
        }

        zxing.setOnClickListener {
            val intent = Intent(this@MainActivity, ZxingActivity::class.java)
            startActivity(intent)
        }
        pic_large.setOnClickListener {
            val intent = Intent(this@MainActivity, ScrollViewActivity::class.java)
            startActivity(intent)
        }
        bt_js.setOnClickListener {
            val intent = Intent(this@MainActivity, JsActivity::class.java)
            startActivity(intent)
        }
        //getDetail();

    }

    /**
     * 网络请求获取商品详情
     */
    //    private void getDetail() {
    //        AndroidNetworking.post("http://tangwu.com/app/login.php")
    //                .addBodyParameter("username", "18737192723")
    //                .addBodyParameter("password", "123")
    //                .setPriority(Priority.MEDIUM)
    //                .build()
    //                .getAsParsed(new TypeToken<Login_Data>() {
    //                }, new ParsedRequestListener<Login_Data>() {
    //                    @Override
    //                    public void onResponse(Login_Data response) {
    //                        Share.d("///" + response.toString());
    //                        // Log.i("TAG", "Detail=" + response.toString());
    //
    //                    }
    //
    //                    @Override
    //                    public void onError(ANError anError) {
    //                        ToastUtils.showToast(MainActivity.this, "222");
    //                    }
    //                });
    //    }


    private var lasttime: Long = 0

    override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean {
        val current = Calendar.getInstance().timeInMillis

        if ((current - lasttime) / 1000 >= 2) {
            val mToast = Toast.makeText(this@MainActivity, "再按一次返回键退出", Toast.LENGTH_SHORT)
            mToast.show()
            lasttime = current
            return true
        } else {
            //AppManager.getAppManager().AppExit()
            System.exit(0)
        }
        return super.onKeyDown(keyCode, event)
    }
}
